package com.zzj.hotel.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;

import com.zzj.hotel.core.entity.Article;
import com.zzj.hotel.dao.ArticleDao;
import com.zzj.hotel.service.ArticleService;

public class ArticleServiceImpl implements ArticleService {
	private ArticleDao articleDao;

	public ArticleDao getArticleDao() {
		return articleDao;
	}

	public void setArticleDao(ArticleDao articleDao) {
		this.articleDao = articleDao;
	}

	public Article findById(String id) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put(Article.ARTICLE_ID, id);
		return articleDao.selectOne(queryMap);
	}

	public List<Article> findAll() {
		return articleDao.selectList(null);
	}

	public List<Article> findList(String articleId) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put(Article.ARTICLE_CLASSIFYID, articleId);
		return articleDao.selectList(queryMap);
	}

	public void deleteArticle(String articleId) {
		articleDao.deleteById(articleId);
	}

	public void addArticle(Article article) {
		articleDao.insert(article);
	}

	public void updateArticle(Article article) {
		articleDao.update(article);
	}

	public List<Article> findList(String articleId, int first, int last,String sort) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put(Article.ARTICLE_CLASSIFYID, articleId);
		return articleDao.selectList(queryMap,first,last,sort);
	}

	public Long getCount(String hql) {
		return articleDao.getCount(hql);
	}

	public List<Article> findList(int first, int last, String sort) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put(Article.ARTICLE_CLASSIFYID, null);
		return articleDao.selectList(queryMap,first,last,sort);
	}
}
